package com.ruoyi.youtian.service.impl;

import java.util.List;

import com.ruoyi.common.annotation.DataScope;
import com.ruoyi.youtian.domain.PointAttribute;
import com.ruoyi.youtian.domain.PointEquipment;
import com.ruoyi.youtian.mapper.PointAttributeMapper;
import com.ruoyi.youtian.mapper.PointEquipmentMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.youtian.mapper.TWorkspacePointMapper;
import com.ruoyi.youtian.domain.TWorkspacePoint;
import com.ruoyi.youtian.service.ITWorkspacePointService;
import com.ruoyi.common.core.text.Convert;

/**
 * 点位与工作区关联Service业务层处理
 * 
 * @author ruoyi
 * @date 2022-09-16
 */
@Service
public class TWorkspacePointServiceImpl implements ITWorkspacePointService 
{
    @Autowired
    private TWorkspacePointMapper tWorkspacePointMapper;

    @Autowired
    private PointEquipmentMapper pointEquipmentMapper;

    @Autowired
    private PointAttributeMapper pointAttributeMapper;

    /**
     * 查询点位与工作区关联
     * 
     * @param id 点位与工作区关联主键
     * @return 点位与工作区关联
     */
    @Override
    public TWorkspacePoint selectTWorkspacePointById(Long id)
    {
        return tWorkspacePointMapper.selectTWorkspacePointById(id);
    }

    /**
     * 查询点位与工作区关联列表
     * 
     * @param tWorkspacePoint 点位与工作区关联
     * @return 点位与工作区关联
     */
    @DataScope(deptAlias = "d")
    @Override
    public List<TWorkspacePoint> selectTWorkspacePointList(TWorkspacePoint tWorkspacePoint)
    {
        return tWorkspacePointMapper.selectTWorkspacePointList(tWorkspacePoint);
    }

    /**
     * 新增点位与工作区关联
     * 
     * @param tWorkspacePoint 点位与工作区关联
     * @return 结果
     */
    @Override
    public int insertTWorkspacePoint(TWorkspacePoint tWorkspacePoint)
    {
        return tWorkspacePointMapper.insertTWorkspacePoint(tWorkspacePoint);
    }

    /**
     * 修改点位与工作区关联
     * 
     * @param tWorkspacePoint 点位与工作区关联
     * @return 结果
     */
    @Override
    public int updateTWorkspacePoint(TWorkspacePoint tWorkspacePoint)
    {
        return tWorkspacePointMapper.updateTWorkspacePoint(tWorkspacePoint);
    }

    /**
     * 批量删除点位与工作区关联
     * 
     * @param ids 需要删除的点位与工作区关联主键
     * @return 结果
     */
    @Override
    public int deleteTWorkspacePointByIds(String ids)
    {
        return tWorkspacePointMapper.deleteTWorkspacePointByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除点位与工作区关联信息
     * 
     * @param id 点位与工作区关联主键
     * @return 结果
     */
    @Override
    public int deleteTWorkspacePointById(Long id)
    {
        return tWorkspacePointMapper.deleteTWorkspacePointById(id);
    }



    @Override
    public int deleteTWorkspacePointByTWorkspacePoint(TWorkspacePoint tWorkspacePoint) {
        PointEquipment pointEquipment = new PointEquipment();
        pointEquipment.setPointId(tWorkspacePoint.getPointId());
        pointEquipment.setUpdateBy(tWorkspacePoint.getUpdateBy());
        pointEquipmentMapper.detetePointEquipmentByPointEquipment(pointEquipment);
        // pointId
        PointAttribute pointAttribute = new PointAttribute();
        pointAttribute.setSceneId(-1L); // 删除默认采集点位上下限值
        pointAttribute.setPointId(tWorkspacePoint.getPointId());
        pointAttribute.setUpdateBy(tWorkspacePoint.getUpdateBy());
        pointAttributeMapper.deletePointAttributeByPointAttribute(pointAttribute);
        // 根据 pointId 和 workspaceCategoryId 确定一条记录
//        TWorkspacePoint tWorkspacePoint = new TWorkspacePoint();
//        tWorkspacePoint.setWorkspaceId(tWorkspaceCategoryPointVo.getWorkspaceCategoryId());
//        tWorkspacePoint.setPointId(tWorkspaceCategoryPointVo.getPointId());
//        tWorkspacePoint.setUpdateBy(tWorkspaceCategoryPointVo.getUpdateBy());
        return tWorkspacePointMapper.deleteTWorkspacePointByTWorkspacePoint(tWorkspacePoint);
    }
}
